package com.chy.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chy.commonutils.Result;
import com.chy.edu.pojo.EduCourse;
import com.chy.edu.pojo.EduTeacher;
import com.chy.edu.service.EduCourseService;
import com.chy.edu.service.EduTeacherService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    @ApiOperation(value = "分页查询讲师")
    @GetMapping("getTeacherFrontList/{current}/{size}")
    public Result getTeacherFrontList(@ApiParam(name = "current", value = "当前页码", required = true)
                                      @PathVariable long current,
                                      @ApiParam(name = "size", value = "每页记录数", required = true)
                                      @PathVariable long size)
    {
        Page<EduTeacher> pageTeacher = new Page<>(current,size);
        Map<String,Object> map = teacherService.getTeacherFrontList(pageTeacher);
        // 返回分页所有数据
        return Result.ok().data(map);
    }

    @ApiOperation(value = "讲师详情功能")
    @GetMapping("getTeacherInfo/{teacherId}")
    public Result getTeacherInfo(@PathVariable String teacherId) {
        // 1.根据讲师id查询讲师基本信息
        EduTeacher eduTeacher = teacherService.getById(teacherId);
        // 2.根据讲师id查询所讲课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);
        return Result.ok()
                .data("teacher",eduTeacher)
                .data("courseList",courseList);
    }
}
